package clientLogin;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class MAJPersonalInfoServlet
 */
public class MAJPersonalInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MAJPersonalInfoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		int id = Integer.parseInt(session.getAttribute("clientID").toString());
		String ln = request.getParameter("lastname");
		String fn = request.getParameter("firstname");
		String ad = request.getParameter("address");
		String ph = request.getParameter("phone");
		String em = request.getParameter("email");
		
		JDBCClientDAO jdbcClient = new JDBCClientDAO();
		Client client = jdbcClient.getByID(id);
		client.setFirstname(fn);
		client.setLastname(ln);
		client.setAddress(ad);
		client.setEmail(em);
		client.setPhone(ph);
		jdbcClient.update(client);
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<head></head>");
		out.println("<body>");
		out.println("You have successfully modified your personal informations");
		out.println("<br/>");
		out.println("<form method=\"POST\" action=\"PersonalCentre.jsp\"><input type=\"submit\" value=\"Return\"></form>");
		out.println("</body>");
	}

}
